clear*
set maxvar 11000

global date _2025_10_28
cd "/Users/atri0032/Dropbox/World Bank/Temperature, poverty, and inequality/Estimations/"

************************************************************************************************
********************************** Figure S1: Subnational poverty and inequality – SPID database
************************************************************************************************

use "${date}/_data/spid_for_analysis_v2.dta", clear

collapse (mean) poor215 gini temp, by(geo_code2_new)

spshape2dta "/Users/atri0032/Dropbox/World Bank/Temperature, poverty, and inequality/Shapefile/am24_subnat_em.shp", saving("worldmap") replace

gen geo_code = geo_code2_new
replace geo_code = subinstr(geo_code,"ADM1","GAUL1",.)

sort geo_code
	merge 1:m geo_code using "worldmap.dta", force
		drop _merge
		drop if _ID==.
		
format poor215 %12.0fc
format gini %12.0fc
	
xtset, clear			
spset, modify shpfile("worldmap_shp.dta")

colorpalette viridis, n(12) nograph reverse

local colors `r(p)'

grmap poor215, fcolor(`r(p)') ocolor(white ..) osize(0.05 ..) legstyle(2) ///
		 legend(label(1 "No data") label(2 "Below 1") label(3 "1-4") label(4 "4-30") ///
		 label(5 "30+") size(vsmall) pos(8) region(fcolor(white))) title("Poverty", size(medium))
		 
graph export "${date}/_figures/_fig_s1a.pdf", as(pdf) replace	
	
colorpalette HCL blues, n(12) nograph reverse

local colors `r(p)'
	
grmap gini, fcolor(`r(p)') ocolor(white ..) osize(0.05 ..) legstyle(2) ///
		 legend(label(1 "No data") label(2 "Below 30") label(3 "30-35") label(4 "35-40") ///
		 label(5 "40+") size(small) pos(8) region(fcolor(white))) title(Inequality, size(medium))
		 
graph export "${date}/_figures/_fig_s1b.pdf", as(pdf) replace	
		 